package com.aaa.java08;

import java.time.LocalDate;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/7/11 14:59
 * @description：
 * @modified By：
 * @version:
 */
public class Wife {
    public static void main(String[] args) {

  /*
        //在构造对象的时候无法屏蔽非法数据
        Person person1= new Person(1,"张三1", LocalDate.of(2000,12,10));
        Person person2= new Person(2,"张三2",LocalDate.of(2003,12,10));
        Person person3= new Person(3,"张三3",LocalDate.of(1999,12,10));
        Person person4= new Person(4,"张三4",LocalDate.of(1987,12,10));
        //在对象生成之后，可以随意的修改对象的属性值
       // person1.birthday=LocalDate.of(5000,12,12);
        //属性被private封装，修改值需要通过set方法进行，可以在set方法中进行值的合法性校验
        person1.setBirthday(LocalDate.of(5000,12,12));

        //person2.name="xxx";
        person2.setName("xxx");
        //创建一个对象数组
        Person[] personArray=new Person[4];
        personArray[0]=person1;
        personArray[1]=person2;
        personArray[2]=person3;
        personArray[3]=person4;
        System.out.println("排序之前的顺序：");
        for (Person person : personArray) {
            System.out.println(person);
        }
        //冒泡排序,外层循环从1始，内层循环减i去
        for (int i = 1; i < personArray.length ; i++) {
            for (int j = 0; j < personArray.length - i; j++) {
                //开始比较出生日期
                if(personArray[j].getBirthday().isAfter(personArray[j+1].getBirthday())){
                    //交换位置
                    //定义一个临时变量，类型取决于数组的类型
                    Person temp= new Person();
                    temp=personArray[j];
                    personArray[j]=personArray[j+1];
                    personArray[j+1]=temp;

                }
            }
        }

        System.out.println("排序之后");
        for (Person person : personArray) {

            System.out.println(person);
        }*/

      /*  Person person = new Person();
        person.id=12;*/
    }
}
